package com.soulkun.smarthome.ui.main.scene

import androidx.databinding.ObservableArrayList
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.soulkun.smarthome.R
import com.soulkun.smarthome.databinding.AppFragmentMainSceneAutoBinding
import com.soulkun.smarthome.logic.model.AutoData
import com.soulkun.smarthome.ui.main.scene.adapter.AppMainSceneAutoListAdapter
import com.soulkun.smarthome.ui.main.scene.viewmodel.AppMainSceneAutoViewModel
import com.soulkun.smarthome.ui.main.scene.viewmodel.AppMainSceneViewModel
import soulkun.library.helper.decoration.LinearSpaceItemDecorationHelper
import soulkun.library.mvvm.adapter.clearAndAddAll
import soulkun.library.mvvm.component.BaseDataBindingFragment

class AppMainSceneAutoFragment: BaseDataBindingFragment<AppFragmentMainSceneAutoBinding>() {

    private val viewModel by lazy {
        ViewModelProvider(
            this,
            ViewModelProvider.AndroidViewModelFactory(mActivity.application)
        ).get(AppMainSceneAutoViewModel::class.java)
    }

    private val adapter by lazy {
        AppMainSceneAutoListAdapter(mContext, autoList)
    }

    private val autoList = ObservableArrayList<AutoData>()

    override fun setLayout(): Int {
        return R.layout.app_fragment_main_scene_auto
    }

    override fun initView() {
        requireDataBinding().rvMainSceneAutoListAuto.layoutManager = LinearLayoutManager(mContext)
        requireDataBinding().rvMainSceneAutoListAuto.adapter = adapter
        requireDataBinding().rvMainSceneAutoListAuto.addItemDecoration(LinearSpaceItemDecorationHelper(10,10,15,15,10))
    }

    override fun initData() {
    }

    override fun initListener() {
        viewModel.autoListLiveData.observe(viewLifecycleOwner){
            autoList.clearAndAddAll(it)
        }
    }

    override fun doOnCreate() {
    }
}